package v1

var (
	ErrHeaderInvalid = newRspMsg(101, "Header中的公共参数无效")
	// common errors
	ErrBadRequest          = newRspMsg(102, "请求参数无效")
	ErrUnauthorized        = newRspMsg(103, "用户未授权")
	ErrNotFound            = newRspMsg(104, "内容不存在")
	ErrInternalServerError = newRspMsg(105, "服务端内部错误")

	//验证码相关
	//验证码发送成功
	SucSendValidCode = newSuccessMsg("验证码发送成功")
	//验证码过期
	ErrValidCodeExpired = newRspMsg(1000, "验证码已过期")
	//验证码不正确
	ErrValidCodeInvalid = newRspMsg(1001, "验证码不正确")
	//验证码发送失败
	ErrValidCodeSendFailed = newRspMsg(1002, "验证码发送失败")
	//验证码已发送
	ErrValidCodeAlreadySend = newRspMsg(1003, "验证码已发送，请稍后再试")

	// more biz errors
	ErrEmailAlreadyUse = newRspMsg(1001, "The email is already in use.")
	//用户已存在
	ErrUserExisted = newRspMsg(1001, "用户已存在")
)

type RspMsg struct {
	code    int
	message string
}

func (e RspMsg) Error() string {
	return e.message
}
func newRspMsg(code int, msg string) RspMsg {
	ret := RspMsg{code: code, message: msg}
	return ret
}

func newSuccessMsg(msg string) RspMsg {
	ret := newRspMsg(0, msg)
	return ret
}
